<?php
apf_require_controller("Abstract");
apf_require_class('Bll_Flow_Info');
apf_require_class('Bll_Flow_Lumesse');
apf_require_class('Flow_Urls');
apf_require_class('Bll_Portal_Message');
apf_require_class('Bll_Report_Report');
apf_require_class("Report_Urls");
class Portal_Home_HomeController extends AbstractController {

    public function handle_request() {
        //2013绽放页面
        $date = date('YmdHis');
        $start = '20130115090000';
        $end   = '20130115145959';
        $data['is_show_active']=0;
        if($date >=$start && $date <= $end){
            //$this->_check_active();
            //$data['is_show_active'] = 1;
        }
        $uid = $this->get_user_id();
        $projects = $this->get_data_bll()->get_sort_projects($uid);
        $id = $this->request->get_parameter("id");
        if (!empty($id) && key_exists($id, $projects)){
            $this->get_data_bll()->inc_view_count($uid, $id);
            $this->response->redirect($projects[$id]['url']);
        }
        //is lumesse user
        $_luser = Bll_Flow_Lumesse::get_instance()->get_user_by_id($uid);
        if(!empty($_luser)){
            $this->request->set_attribute('is_lumesse_user', 'true');
        }else{
            $this->request->set_attribute('is_lumesse_user', 'false');
        }
        //报表权限
        $report_bll = new Bll_Report_Report();
        $count = $report_bll->check_view_auth($this->user_info['user_id']);
        $this->request->set_attribute('view_department', $count);

        $this->request->set_attribute('role_list', $this->user_info['role_list']);
        $this->request->set_attribute('data', $data);
        $this->request->set_attribute('myinfo', $this->user_info);
        $this->request->set_attribute('projects', $projects);
        return "Portal_Home_Home";
    }

    private function get_data_bll(){
        if (!$this->data_bll || !$this->data_bll instanceof Bll_Portal_HomeProjectView){
            apf_require_class("Bll_Portal_HomeProjectView");
            $this->data_bll = new Bll_Portal_HomeProjectView();
        }
        return $this->data_bll;
    }
    /**
     * 2013绽放页面
     * @return boolean
     */
    private function _check_active(){
        $uid = $this->get_user_id();
        $bll = new Bll_Portal_Message();
        $data = $bll->get_message($uid);
        if(empty($data)){
            $this->response->redirect(Portal_Urls::build_active());return ;
        }
    }
}